#ifndef _SOCKET_BASE_H_
#define _SOCKET_BASE_H_

#include <map>
#include <string>
#include "qbuffer.h"

class Socket
{
public:
    Socket() {}
    Socket(int s) : _fd(s) {}
    virtual ~Socket() {}
    
    int Id() {return _fd;}
    void Open(const std::string& ip, unsigned short p);
    void Send(SharedBuffer data);
private:
    int _fd {-1};
};

class SocketMGR
{
public:
    SocketMGR() {}

    ///生成一个新的socket
    static Socket* NewConnect(const std::string& ip, unsigned short p);

    ///绑定label和socket
    void Insert(const std::string& label, int s);
    Socket* Get(const std::string& label);
private:
    std::map<std::string, Socket*> _fds;
};

static Socket* s_invalid_socket = new Socket();

#endif
